﻿

''' <summary>
''' 冷风机端口服务类
''' </summary>
''' <remarks></remarks>
Public Class CcapAirCoolerPortItemService

    ''' <summary>
    ''' 默认构造函数
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub New()

    End Sub


    ''' <summary>
    ''' 查询冷风机的端口
    ''' </summary>
    ''' <param name="acId">冷风机编号</param>
    ''' <returns>返回冷风机端口信息</returns>
    ''' <remarks>数据集包换字段：Id,acId,acDefPreAlarmPort</remarks>
    Public Function GetPorts(ByVal acId As Integer) As DataSet
        Dim ds As DataSet = Nothing
        Dim strSql As String = String.Empty

        strSql = "SELECT Id,acId,acDefPreAlarmPort " + _
                " FROM `tbccAirCoolerPortSet` WHERE acId = " + acId.ToString()

        Try
            ds = SqlHelper.ExecuteDataset(strSql, Nothing)
        Catch ex As Exception
            ds = Nothing
        End Try

        Return ds
    End Function


    ''' <summary>
    ''' 查询项目包含的冷风机及报警端口
    ''' </summary>
    ''' <param name="projectId">项目编号</param>
    ''' <returns> Id, ceId, csNetId, name, acDefPreAlarmPort</returns>
    ''' <remarks></remarks>
    Function GetGroupNameAndPorts(ByVal ProjectId As String) As DataSet
        Dim ds As DataSet = Nothing
        Dim strSql As String = String.Empty

        strSql = " SELECT P.Id, P.AcId, C.csNetId, C.name, P.acDefPreAlarmPort " & _
                " FROM tbccaircoolerportset AS P Inner Join tbccaircooler AS C ON P.acId = C.Id " & _
                " Inner Join tbcccompressorset AS G ON G.Id = C.csId Inner Join tbccccapdevtype AS T ON T.Id = G.DevId " & _
                " WHERE T.csNetId>=50  And T.ProjectID='" + ProjectId + "'"
        Try
            ds = SqlHelper.ExecuteDataset(strSql, Nothing)
        Catch ex As Exception
            ds = Nothing
        End Try

        Return ds
    End Function
    ''' <summary>
    ''' 更新制冷全局端口
    ''' </summary>
    ''' <param name="Com"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function InsertAirCoolerPort(ByVal Com As CcapAirCoolerPortItem) As Boolean
        Dim strSql As String
        Dim tic As New TBCC.Utility.TranstrationItem


        strSql = String.Format("delete from tbccaircoolerportset where acId='{0}'", Com.AcId)
        tic.Add(strSql, Nothing)
        strSql = "Insert into tbccaircoolerportset(acId,acDefPreAlarmPort) Values(?p0,?p1)"

        Dim p1(1) As System.Data.Common.DbParameter

        p1(0) = New MySql.Data.MySqlClient.MySqlParameter()
        p1(0).ParameterName = "p0" : p1(0).Value = Com.AcId

        p1(1) = New MySql.Data.MySqlClient.MySqlParameter()
        p1(1).ParameterName = "p1" : p1(1).Value = Com.acDefPreAlarmPort




        tic.Add(strSql, p1)


        Return TBCC.Utility.SqlHelper.ExecuteTranstration(tic)

    End Function
End Class
